package com.crm.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.crm.dao.SysRightMapper;
import com.crm.model.SysRight;

@Service
public class RightService implements IRightService {
	@Autowired
	private SysRightMapper sysRightMapper;

	
	public List<SysRight> showRight(Integer usrRoleId,Integer rightParentCode){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("usrRoleId", usrRoleId);
		map.put("rightParentCode", rightParentCode);
		
		List<SysRight> list = sysRightMapper.list(map);
		
		List<SysRight> sysRights = new ArrayList<SysRight>();
		
		for (SysRight sysRight : list) {
			rightParentCode = sysRight.getRightCode();
		
			List<SysRight> list2 = showRight(usrRoleId,rightParentCode);
			
			if(list2.size() == 0){
				sysRight.setSysRights(null);
			}else{
				sysRight.setSysRights(list2);
			}
			sysRights.add(sysRight);
		}

		
		return sysRights;
		
	}
	
	
	
	
	
}
